package com.orange.stat.schedule;

import com.orange.stat.service.DailyService;
import com.orange.stat.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author orange
 * @email orangestart@yeah.net
 * @create 2021-12-29 21:14
 * 定时任务
 */
@Component
public class ScheduleTask {

    @Autowired
    private DailyService dailyService;

    //（0/5 * * * * ？）：每隔5秒执行一次
    /*@Scheduled(cron = "0/5 * * * * ?")//指定cron表达式规则
    public void taskDemo(){
        System.out.println("========定时任务测试=========");
    }*/

    //每天凌晨1点执行方法，把前一天的数据查询进行添加
    @Scheduled(cron = "0 0 1 * * ? ")//指定cron表达式规则
    public void task(){
        dailyService.createStatisticsByDay(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
